package hutech.ksv.view;

import hutech.ksv.entity.QuanAnDataModel;
import hutech.ksv.entity.ThongTinQuanAnEntity;
import hutech.ksv.service.DuyetQuanAnService;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


@Component
@Scope("request")
public class DuyetQuanAnManagedBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private QuanAnDataModel quanAnDataModel;
	private List<ThongTinQuanAnEntity> selectedQuanAn;
	private List<ThongTinQuanAnEntity> danhSachThongTinQuanAn;
	
	
	public QuanAnDataModel getQuanAnDataModel() {
		return quanAnDataModel;
	}

	public void setQuanAnDataModel(QuanAnDataModel quanAnDataModel) {
		this.quanAnDataModel = quanAnDataModel;
	}

	public List<ThongTinQuanAnEntity> getSelectedQuanAn() {
		return selectedQuanAn;
	}

	public void setSelectedQuanAn(List<ThongTinQuanAnEntity> selectedQuanAn) {
		this.selectedQuanAn = selectedQuanAn;
	}

	public List<ThongTinQuanAnEntity> getDanhSachThongTinQuanAn() {
		return danhSachThongTinQuanAn;
	}

	public void setDanhSachThongTinQuanAn(
			List<ThongTinQuanAnEntity> danhSachThongTinQuanAn) {
		this.danhSachThongTinQuanAn = danhSachThongTinQuanAn;
	}

	@Autowired
	DuyetQuanAnService duyetQuanAnService;
	
	@PostConstruct
	public void init() {
		danhSachThongTinQuanAn = duyetQuanAnService.getTatCaThongTinQuanAn();
		quanAnDataModel = new QuanAnDataModel(danhSachThongTinQuanAn);
	}
	
	public void onLoad() {
		selectedQuanAn = null;
		danhSachThongTinQuanAn = duyetQuanAnService.getTatCaThongTinQuanAn();
		quanAnDataModel = new QuanAnDataModel(danhSachThongTinQuanAn);
	}
	
	public String duyetQuanAn() {
		for(ThongTinQuanAnEntity thongTinQuanAnEntity : selectedQuanAn) {
			duyetQuanAnService.duyetQuanAn(thongTinQuanAnEntity.getMaQA());
		}				
		return "DuyetQuanAn";
	}

}
